package com.binarysoft.service.obj.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.binarysoft.service.obj.dao.ObjectProperty;

public class ObjectPropertySqlProvider {

    public String insertSelective(ObjectProperty record) {
        BEGIN();
        INSERT_INTO("object_property");
        
        VALUES("obj_id", "#{objId,jdbcType=INTEGER}");
        
        if (record.getPropId() != null) {
            VALUES("prop_id", "#{propId,jdbcType=VARCHAR}");
        }
        
        if (record.getPropName() != null) {
            VALUES("prop_name", "#{propName,jdbcType=VARCHAR}");
        }
        
        if (record.getPropValue() != null) {
            VALUES("prop_value", "#{propValue,jdbcType=VARCHAR}");
        }
        
        if (record.getIsLocked() != null) {
            VALUES("is_locked", "#{isLocked,jdbcType=BIT}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(ObjectProperty record) {
        BEGIN();
        UPDATE("object_property");
        
        if (record.getPropName() != null) {
            SET("prop_name = #{propName,jdbcType=VARCHAR}");
        }
        
        if (record.getPropValue() != null) {
            SET("prop_value = #{propValue,jdbcType=VARCHAR}");
        }
        
        if (record.getIsLocked() != null) {
            SET("is_locked = #{isLocked,jdbcType=BIT}");
        }
        
        WHERE("obj_id = #{objId,jdbcType=INTEGER}");
        WHERE("prop_id = #{propId,jdbcType=VARCHAR}");
        
        return SQL();
    }
}